package com.zhiketuan.webserver.controllers.api;

import com.zhiketuan.webserver.domain.SysAdmin;
import com.zhiketuan.webserver.model.ResponseResult;
import com.zhiketuan.webserver.model.Responses;
import com.zhiketuan.webserver.service.SysAdminService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 系统管理费用员控制器
 *
 * @author 凡梦星尘(elkan1788@gmail.com)
 */
@RestController
@RequestMapping(value="/api/sysadmin", produces=MediaType.APPLICATION_JSON_VALUE)
@Api(value="SysAdmin-API", description="系统管员表操作方法", produces="application/json")
public class SysAdminController {

    @Autowired
    private SysAdminService sysAdminService;

    @RequestMapping(value="/add", method=RequestMethod.PUT, consumes=MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(notes="添加新的系统管理员", httpMethod="PUT", value = "添加")
    @ResponseBody
    public ResponseEntity<ResponseResult> addSysAdmin(@ApiParam(required=true, value="管理员信息")@RequestBody SysAdmin sysAdmin) {
        ResponseResult result = sysAdminService.saveSysAdmin(sysAdmin);
        return Responses.ok(result);
    }

    @RequestMapping(value="/update", method=RequestMethod.POST, consumes=MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(notes="更新系统管理员", httpMethod="POST", value = "更新")
    @ResponseBody
    public ResponseEntity<ResponseResult> updateSysAdmin(@ApiParam(required=true, value="管理员信息")@RequestBody SysAdmin sysAdmin) {
        ResponseResult result = sysAdminService.updateSysAdmin(sysAdmin);
        return Responses.ok(result);
    }

    @RequestMapping(value="/delete", method=RequestMethod.DELETE)
    @ApiOperation(notes="删除系统管理员", httpMethod="DELETE", value = "删除")
    @ResponseBody
    public ResponseEntity<ResponseResult> updateSysAdmin(@ApiParam(required=true, value="管理员ID")@RequestParam(value = "adminId") Integer adminId) {
        ResponseResult result = sysAdminService.deleteSysAdmin(adminId);
        return Responses.ok(result);
    }

    @RequestMapping(value="/findByAct", method=RequestMethod.GET)
    @ApiOperation(notes="查找系统管理员", httpMethod="GET", value = "查询")
    @ResponseBody
    public ResponseEntity<ResponseResult> findSysAdmin(
            @ApiParam(value="管理账号", required=true) @RequestParam(value="account") String account) {

        ResponseResult result = this.sysAdminService.searchSysAdminByAct(account);

        return Responses.ok(result);
    }
}
